package com.example.demo.web;

import com.example.demo.api.model.SeataOrder;
import com.example.demo.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("business")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @GetMapping("test")
    public ResponseEntity<SeataOrder> pur(){

        SeataOrder order = businessService.purchase(1, "1", 50);
        return ResponseEntity.ok(order);
    }

    @GetMapping("test1")
    public ResponseEntity<SeataOrder> pur1(){

        SeataOrder order = businessService.purchase(1, "1", 10);
        return ResponseEntity.ok(order);
    }

    @PostMapping("purchase")
    public ResponseEntity purchase(Integer userId, String commodityCode, int orderCount) {
        businessService.purchase(userId, commodityCode, orderCount);
        return ResponseEntity.ok().build();
    }
}
